<?php
   session_start();
   if($_SESSION['uname']){
   $uname=$_SESSION['uname'];
   $logout="<form action=\"logout_resource.php\" method=\"post\" name=\"logout\">
            <input type=\"submit\" name=\"logout\" value=\"退出登录\" /></form>";}
if($_POST['submit']){
   require_once 'validate.php';
   $uname=$_SESSION['uname'];   
   if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo "<script>alert('上传失败，该文件已经存在！');</script>";
      }
    else
      {
      require_once 'dbconn.php';
      $time=date("Y-n-d H:i:s");
      $title=$_FILES["file"]["name"];
      $url="upload/" . $_FILES["file"]["name"];
      $query="insert into resource(author,time,title,url) values('$uname','$time','$title','$url')";
      $result=$db->sql_query($query);
       if ($result){
            echo "<script>alert('上传成功！');location.href='resource.php'</script>";//刷新
            move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
       }
      }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>资源共享</title>
<link href="css/twoColFixLtHdr.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function setcolor(){
	for(var i=1;i<tb_share.rows.length;i++){
		if (i%2==0){
			tb_share.rows[i].bgColor="#efefef";
		}else{
			tb_share.rows[i].bgColor="#ffffff";
		}
	}
}
</script>
</head>
<body class="twoColFixLtHdr" onLoad="javascript:setcolor();">
<div id="logo"></div>
<div id="navi"><table border="0" cellpadding="0" cellspacing="0"><tr>
<?php
require_once 'dbconn.php';
$sql="select * from module";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrowset($result);
require_once 'resource_list.php';
foreach($row as $arr)
{
$modname=$arr['modname'];
$modhref=$arr['modhref'];
navi_list($modname,$modhref);
}
?>
</tr></table>
</div>
<div id="container">
<br /><h1>IBM俱乐部资源中心</h1>
<hr size="5" color="#9D9D9D" />
<hr size="5" color="#9D9D9D" />
</div>
<div id="container">
<table width="960" cellpadding="0" cellspacing="0" border="0" id="table">
<tr><th height="40" style="text-align:center;"><?php echo $uname; ?>你好！欢迎来到IBM俱乐部资源中心！&nbsp;&nbsp;&nbsp;&nbsp;
<?php echo $logout; ?></th></tr>
<tr><td height="40" style="vertical-align:middle; text-align:right">
<form action="" method="post" enctype="multipart/form-data">
<label for="file">文件名：</label>
<input type="file" name="file" id="file" /> 
<input type="submit" name="submit" value="上传资源" />
</form>
</td></tr>
<tr><td height="600" style="vertical-align:top;">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="1" id="tb_share">
  <tr>
    <th width="400">资源名</th>
    <th width="200">上传时间</th>
    <th width="100">上传者</th>
    <th width="100">下载资源</th>
  </tr>  
<?php
//require_once 'dbconn.php';
$sql="select title,author,url,to_char(time, 'YYYY-MM-DD  HH24:MI:SS') from resource order by time desc";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrowset($result);
//require_once 'resource_list.php';
foreach($row as $arr)
{
$author=$arr['author'];
$title=$arr['title'];
$time=$arr['to_char'];
$url=$arr['url'];
resource_list($title,$time,$author,$url);
}
?>
</table>
</td></tr></table>
</div>
<div id="footer">
<p>Copyright © 2010 IBM club,Shenzhen University, All Rights Reserved.</p></div>
</div>
</body>
</html>
